package com.wyh.aop.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Aspect
@Component
@Order
public class AspectDemo1 {
    @Pointcut("execution(* com.wyh.aop.controller.*.*(..))")
    public void p(){}

    @Before("p()")
    public void doBefore(){
        System.out.println("------------------------doBefore......-------------------");
        ServletRequestAttributes request = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        System.out.println(request.getRequest());
        System.out.println("1");
    }

    @Around("p()")
    public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("before");
        Object ret = proceedingJoinPoint.proceed();
        System.out.println("after");
        return ret;
    }

    @After("p()")
    public void doAfter(){
        System.out.println("doAfter");
    }
}
